cmake_minimum_required(VERSION 3.8)
project(sensor_fusion)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 寻找依赖包
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(message_filters REQUIRED)
# 添加Service所需依赖
find_package(rosidl_default_generators REQUIRED)

include_directories(${EIGEN3_INCLUDE_DIR})

# 声明Service文件
set(srv_files
  "srv/SensorStatus.srv"
)

# 生成Service接口代码
rosidl_generate_interfaces(${PROJECT_NAME}
  ${srv_files}
  DEPENDENCIES builtin_interfaces
)

# 编译摄像头节点
add_executable(camera_node src/camera_node.cpp)
ament_target_dependencies(camera_node
  rclcpp
  sensor_msgs
  cv_bridge
  OpenCV
)

# 编译激光雷达节点
add_executable(lidar_node src/lidar_node.cpp)
ament_target_dependencies(lidar_node
  rclcpp
  sensor_msgs
)

# 编译融合节点
add_executable(fusion_node src/fusion_node.cpp)
ament_target_dependencies(fusion_node
  rclcpp
  sensor_msgs
  cv_bridge
  OpenCV
  Eigen3
  message_filters
)

# 链接Service接口库
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(camera_node "${cpp_typesupport_target}")
target_link_libraries(lidar_node "${cpp_typesupport_target}")
target_link_libraries(fusion_node "${cpp_typesupport_target}")

# 安装可执行文件
install(TARGETS
  camera_node
  lidar_node
  fusion_node
  DESTINATION lib/${PROJECT_NAME})

# 安装启动文件和服务定义
install(DIRECTORY
  launch
  srv
  DESTINATION share/${PROJECT_NAME})

ament_package()